package com.jtpay.sdk.activity;

import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.channel.test.DaoSession;
import com.jtpay.sdk.BuildConfig;
import com.jtpay.sdk.app.JftApplication;
import com.jtpay.sdk.util.GlobalUtil;

import de.greenrobot.dao.query.QueryBuilder;

/**
 * Created by Steven on 2016/10/13 0013.
 * update by Joe
 * add greenDao DataBase operation
 */

public class BaseActivity extends AppCompatActivity {
    protected SQLiteDatabase db;
    protected DaoSession daoSession;

    public BaseActivity() {

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        JftApplication.getInstance().addActivity(this);
        initBaseDatas();
    }

    private void initBaseDatas() {
        // 在 QueryBuilder 类中内置两个 Flag 用于方便输出执行的 SQL 语句与传递参数的值
        if (BuildConfig.DEBUG) {
            QueryBuilder.LOG_SQL = true;
            QueryBuilder.LOG_VALUES = true;
        } else {
            QueryBuilder.LOG_SQL = false;
            QueryBuilder.LOG_VALUES = false;
        }
    }

    protected void setupDatabase() {
        //基类获得数据库连接和 daoSession对象
        db = GlobalUtil.getInstance().getSQLiteDatabase();
        daoSession = GlobalUtil.getInstance().getDaoSession();
    }
}
